<template>
	<view>
		<table>
			<tr>
				<td>id={{id}}</td>
				<td>商品名</td>
				<td>商品价格</td>
				<td>商品重量</td>
				<td>商品存量</td>
			</tr>
			<tr>
				<td>修改前</td>
				<td>{{good.Name}}</td>
				<td>{{good.Price}}</td>
				<td>{{good.Kg}}</td>
				<td>{{good.Stock}}</td>
			</tr>
			<tr>
				<td>修改后</td>
				<td><input type="text" value="" v-model="name"/></td>
				<td><input type="text" value="" v-model="price"/></td>
				<td><input type="text" value="" v-model="kg"/></td>
				<td><input type="text" value="" v-model="stock"/></td>
			</tr>
		</table>
		<button type="default">修改</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:"",
				good:{},
				name:"",
				price:"",
				kg:"",
				stock:"",
			}
		},
		onLoad: function (option) {
				console.log(option.id);
				this.id=option.id
				this.get()
			},
		methods: {
			get(){
				uni.request({
				    url: 'http://127.0.0.1:8080/update', //仅为示例，并非真实接口地址。
				    data: {
				       id:this.id
				    },
				    header: {
				        'custom-header': 'hello' //自定义请求头信息
				    },
				    success: (res) => {
				        console.log(res.data);
						this.good=res.data.Data
				    }
				});
			},
			update(){
				uni.request({
				    url: 'http://127.0.0.1:8080/update', //仅为示例，并非真实接口地址。
					method:"POST",
				    data: {
				       id:this.id,
					   price:this.price,
					   kg:this.kg,
					   stock:this.stock,
					   name:this.name
				    },
				    header: {
				        'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
				    },
				    success: (res) => {
				        console.log(res.data);
						uni.reLaunch({
							url: '../index/index'
						});
				    }
				});
			},
		}
	}
</script>

<style>

</style>
